package com.leyou.item.controller;

import com.leyou.item.pojo.Category;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("category")
public class CategoryController {
    @Autowired
    private CategoryService categoryServiceimpl;
    @GetMapping("list")
    public ResponseEntity<List<Category>> queryByParentId(@RequestParam("pid")Long pid){
        List<Category> categories =  this.categoryServiceimpl.queryByParentId(pid);
        if(categories!=null){
            return ResponseEntity.ok(categories);
        }
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }
    @GetMapping("bid/{bid}")
    public ResponseEntity<List<Category>> queryByBrandId(@PathVariable("bid")Long bid){
        List<Category> categories = this.categoryServiceimpl.queryByBrandId(bid);
        if (categories != null && 0!=categories.size()) {
            return ResponseEntity.ok(categories);
        }

        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();//204
    }
}
